#!/usr/bin/python
#-*- coding: utf-8 -*-

import sqlite3

con = sqlite3.connect('mesh_sqlite.db')
cur = con.cursor()

MN = 'C04.651.600'

# Find parent terms
mesh_list = []

print "Parent Terms"
for MN_id in MN.split('.'):
    mesh_list.append(MN_id)
    id = ".".join(mesh_list)
    query = "SELECT * FROM  mesh WHERE MN = '" + id + "'"
    cur.execute(query)
    
    for row in cur:
        print row[0] + " => " + row[1]

#  Find child terms
query = "SELECT * FROM mesh WHERE MN like '" + MN + ".%' ORDER BY MN"
cur.execute(query)

print "Child Terms"
for row in cur:
    print row[0] + " => " + row[1]